package com.cloudcc.mobile.manager;

import android.content.Context;

import com.cloudcc.cloudframe.CApplication;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppConfig;
import com.cloudcc.mobile.util.PreferenceUtils;

/** 应用程序运行时 产生的数据 用户注销的时候会清空
* @Description: TODO() 
* @author wangzhiqiang
* @date 2016-3-2 下午2:21:08 
*  
*/
public class RunTimeManager {

	private static RunTimeManager instance;
	
	private CApplication app;
	
	private final String XML = AppConfig.XML_APP;

	private RunTimeManager(Context app) {
		this.app =(CApplication) app;
	}

	public synchronized static RunTimeManager getInstance() {
		if (instance == null) {
			instance = new RunTimeManager(CApplication.getApp());
		}
		return instance;
	}

	/**
	 * 获得 服务器的binding
	 * 
	 * @return
	 */
	public String getServerBinding() {
		return StringUtils.isBlank(app.binding) ? StringUtils.EMPTY
				: CApplication.binding;
	}
	
	/**
	 * 设置 最后一次登录时间
	 * @param time
	 */
	public void setLoginTime(long time){
		((CApplication)CApplication.getApp()).lastLoginTime =time;
	}
	/**
	 * 获得最后一次登录的时间
	 * @return
	 */
	public long getLastLoginTime(){
		return ((CApplication)CApplication.getApp()).lastLoginTime;
	}
	
	

	/** 
	* 设置会话binding
	* @param binding
	*/ 
	public static void setAppBinding(String binding) {
		CApplication.binding = binding;
	}
	
	/**
	 * 设置动态类型
	 * 
	 * @param dynamicType
	 */
	public void setDynamicType(String dynamicType) {
		PreferenceUtils.commitString(app, XML, DYNAMIC_TYPE,
				dynamicType);
	}

	/**
	 * 获得动态类型
	 * 
	 * @return
	 */
	public String getDynamicType() {
		return PreferenceUtils.getString(app, XML, DYNAMIC_TYPE,
				AppConfig.DYNAMIC_TYPE);
	}
	
	private static final String MODEL_USER = "model.test";
	
	/** 获得是否是快速体验模式
	 * @return
	 */
	public boolean isTestModel(){
		return PreferenceUtils.getBoolean(app, XML, MODEL_USER,false); 
	}
	/**设置是否是快速体验模式
	 * @param isTest
	 */
	public void setTestModel(boolean isTest){
		PreferenceUtils.commitBoolean(app, XML, MODEL_USER, isTest);
	}
	
	
	
	
	/**
	 * 保存的类型
	 */
	private static final String DYNAMIC_TYPE = "dynamic.type";
	
	/** 
	* 清空用户数据
	*/ 
	public void clearUserCache(){
		setAppBinding("");
		PreferenceUtils.clear(app, AppConfig.XML_VAR);
		PreferenceUtils.clear(app,XML);
	}
	
	public interface DynamicType {
		/**
		 * 我追随的内容
		 */
		String FOLLOW = "follow";

		/**
		 * 设计我的更新
		 */
		String ME = "me";

		/**
		 * 我收藏的微帖
		 */
		String MARK = "mark";

		/**
		 * 全部
		 */
		String COMPANY = "company";
	}

}
